<?php
//权限判断
session_start();
require_once('check.php');
require_once('../system/conndb.php');
//可以加上 $_POST['']的判断
$videoname = trim($_POST["videoname"]);
$videotype = $_POST["videotype"];
$videointro = $_POST["videointro"];
$istop =  $_POST["istop"];

if($_FILES['pic']['error']>0){
	echo "error";
	//增加返回链接
	exit;
}
else{
	

$suffix = strrchr($_FILES["pic"]["name"],".");
//增加判断后缀是否在允许的范围内
$allowtype = array("jpg","jpeg","png","gif","Bmp","flv");
if(!in_array(ltrim($suffix,'.'),$allowtype)){
	echo "文件类型为$suffix!<br/>";
	echo "文件类型不正确！只能选择扩展名为jpg,jpeg,png,gif,Bmp,flv类型的文件！";
	exit;	
}
//指定在服务器上文件存放路径和文件名
$filepath = "../uploads/poster/";
$newname = date("YmdHis").rand(100,999).$suffix;
if(!move_uploaded_file($_FILES["pic"]["tmp_name"],
  $filepath.$newname))
  die("上传失败");
$pic = $newname;
	
}

//echo $pic;
//exit;
//视频上传
if($_FILES['address']['error']>0){
	echo "error";
	//增加返回链接
	exit;
}
else{

$suffix = strrchr($_FILES["address"]["name"],".");
//增加判断后缀是否在允许的范围内
$allowtype = array("mp4");
if(!in_array(ltrim($suffix,'.'),$allowtype)){
	echo "文件类型为$suffix!<br/>";
	echo "文件类型不正确！只能选择扩展名为mp4类型的文件！";
	exit;	
}
//指定在服务器上文件存放路径和文件名
$filepath = "../uploads/video/";
$newname = date("YmdHis").rand(100,999).$suffix;
if(!move_uploaded_file($_FILES["address"]["tmp_name"],
  $filepath.$newname))
  die("上传失败");
$address = $newname;
	
}
//echo $address;
//exit;
$uploadadmin = $_SESSION['adminid'];
$sql = "insert into videos values(null,
'$videoname',$videotype,'$pic','$videointro',now(),$uploadadmin,0,0,'$address',$istop)";

echo $sql;
//exit;
$link = connect();
$result = mysqli_query($link,$sql);
//var_dump($result);exit;
//$num= mysqli_affected_rows($result);
if($result){
	echo "添加成功！2秒后自动跳转！";
	 header("Refresh:2;url=videolist.php");
}
else
{
   echo "操作异常！";
   echo '<a href="javascript:history.go(-1);">返回上一页</a>';	
}

?>